home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Debug.h
-
- Contains: Simple debug macros for use with debug window.
-
- Usage:
- You need extra parentheses since this is done with the preprocessor
- e.g. PRINT(("hello world..."))
-
- Written by: Bruce Horn, Steve Capps, Larry Kenyon,
- John Meier, scott douglass, Darin Adler,
- Paul Mercer, Bryan Stearns, Dave Owens,
- Jeff Miller
-
- Copyright: © 1988-1990, 1993-1994 by Apple Computer, Inc., all rights reserved.
-
- 2/23/95 ga
- <11> 10/13/94 ga
- */
-
- #ifndef Debug_h
- #define Debug_h
-
- //
- // It would be better to set this in some sort of
- // build-configuration file, but MW doesn't conveniently
- // support that at the moment.
- //
- #define DEBUG 1
-
-
- #include <Types.h>
-
- // actual debug functions and macros
-
- extern void dbgAssertPrint(const char*, ...);
- extern void dbgAssert(const char* filename, SInt32 line);
- extern void dbgGuard(const char* filename, SInt32 line);
- extern void dbgInvalidPointer(const void* pointer, const char* filename, SInt32 line);
- extern void dbgInvalidHandle(const void** handle, const char* filename, SInt32 line);
-
-
- #ifdef DEBUG
-
- #define INLINEASSERT(what) { if (!(what)) Debugger(); }
-
- #define INITIALIZEDEBUG()
- #define TERMINATEDEBUG()
- #define DEBUGEVENT(event)
-
- #define BLOCKPRINT(args) { dbgAssertPrint args; }
- #define PRINT(args) do BLOCKPRINT(args) while (0)
- #define CAPSPRINT(args) ASSERTPRINT(!CapsLockCurrentlyDown(), args)
-
- #define BLOCKPRINTNOT(what, args) { if (what) { dbgAssertPrint args; } }
- #define PRINTNOT(what, args) do BLOCKPRINTNOT(what, args) while (0)
- #define CAPSPRINTNOT(what, args) ASSERTPRINT(((!CapsLockCurrentlyDown()) && (what)), args)
-
- #define BLOCKASSERTPRINT(what, args) { if (!(what)) { dbgAssertPrint args; } }
- #define ASSERTPRINT(what, args) do BLOCKASSERTPRINT(what, args) while (0)
- #define CAPSASSERTPRINT(what, args) ASSERTPRINT(!CapsLockCurrentlyDown() || (what), args)
-
- #define BLOCKASSERT(what) { if (!(what)) dbgAssert(__FILE__,__LINE__); }
- #define ASSERT(what) do BLOCKASSERT(what) while(0)
- #define CAPSASSERT(what) ASSERT(!CapsLockCurrentlyDown() || (what))
-
- #define ASSERTNOERR(what) ASSERT((what) == noErr)
- #define CAPSASSERTNOERR(what) ASSERT(!CapsLockCurrentlyDown() || ((what) == noErr))
-
-
- #define BLOCKGUARD(object, className) { if (!((object) && (object)->DerivedFrom(className))) dbgGuard(__FILE__,__LINE__); }
- #define GUARD(object, className) do BLOCKGUARD(object, className) while (0)
-
- #define BLOCKREQUIREVALIDPOINTER(ptr) { dbgInvalidPointer(ptr, __FILE__,__LINE__); }
- #define REQUIREVALIDPOINTER(ptr) do BLOCKREQUIREVALIDPOINTER(ptr) while (0)
-
- #define BLOCKREQUIREVALIDHANDLE(handle) { dbgInvalidHandle(handle, __FILE__,__LINE__); }
- #define REQUIREVALIDHANDLE(handle) do BLOCKREQUIREVALIDHANDLE(handle) while (0)
-
-
- // use to catch bad method calls
-
- #define ABSTRACTBASE() ASSERT(false)
-
- #else // DEBUG
-
- // non-debug versions
-
- #define INLINEASSERT(what)
-
- #define INITIALIZEDEBUG()
- #define TERMINATEDEBUG()
- #define DEBUGEVENT(event)
-
- #define MEASUREBLOCK()
- #define MEASUREPERFORMANCE()
- #define PERFORMANCEON()
- #define PERFORMANCEOFF()
-
- #define BLOCKPRINT(args) {}
- #define PRINT(args) ((void)0)
- #define CAPSPRINT(args) ((void)0)
-
- #define BLOCKPRINTNOT(what, args) {}
- #define PRINTNOT(what,args) ((void)0)
- #define CAPSPRINTNOT(what,args) ((void)0)
-
- #define BLOCKASSERTPRINT(what, args) {}
- #define ASSERTPRINT(what,args) ((void)0)
- #define CAPSASSERTPRINT(what,args) ((void)0)
-
- #define BLOCKASSERT(what) {}
- #define ASSERT(what) ((void)0)
- #define CAPSASSERT(what) ((void)0)
-
- #define ASSERTNOERR(what) ((void)0)
- #define CAPSASSERTNOERR(what) ((void)0)
-
- #define BLOCKGUARD(object, className) {}
- #define GUARD(object, className) ((void)0)
-
- #define BLOCKREQUIREVALIDPOINTER(ptr) {}
- #define REQUIREVALIDPOINTER(ptr) ((void)0)
-
- #define BLOCKREQUIREVALIDHANDLE(handle) {}
- #define REQUIREVALIDHANDLE(handle) ((void)0)
-
- #define ABSTRACTBASE() ((void)0)
-
- #endif // DEBUG
-
- #endif // debug_h
-
-